#include <stdio.h>
#include <string.h>
#include <assert.h>

void* my_memmove(void* dest, const void* src, size_t num)
{
    assert(dest && src);
    void* ret = dest;
    if(dest < src)
    {
        //前--->后
        while(num--)
        {
            *(char*)dest = *(char*)src;
            dest = (char*)dest + 1;
            src = (char*)src + 1;
        }
    }
    else
    {
        //后--->前
        while(num--)
        {
            *((char*)dest + num) = *((char*)src + num);
        }
    }
    return ret;
}

int main(void)
{
    int arr[] = {1,2,3,4,5,6,7,8,9,10};
    
    my_memmove(arr+2,arr,5*sizeof(int));
    
    int i = 0;
    for(i = 0; i<10; i++)
    {
        printf("%d ", arr[i]);
    }
    return 0;
}
